//订单查询
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            storeOrderCartReturnInfo: {
                orderCarts: [],
                total: 0,
                records: 1,
                orderDetail: false,
                states: [],
                conditions: {
                    cartId: '',
                    state: '',
                    prodName: '',
                    shopId: ''
                },
                curOrderCart: {}
            }
        },
        _initMethod: function () {
            $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('store_order_cart_return', "state", function (_data) {
                $that.storeOrderCartReturnInfo.states = _data;
            });
        },
        _initEvent: function () {
            vc.on('storeOrderCartReturn', 'goBack', function (_param) {
                $that.storeOrderCartReturnInfo.orderDetail = false;
            });
            vc.on('storeOrderCartReturn', 'list', function () {
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('storeOrderCartReturn', 'auditNotify', function (_param) {
                $that._doOpenAuditReturnOrderCartModel(_param);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listOrders(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listOrders: function (_page, _rows) {
                $that.storeOrderCartReturnInfo.conditions.page = _page;
                $that.storeOrderCartReturnInfo.conditions.row = _rows;
                $that.storeOrderCartReturnInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                let param = {
                    params: $that.storeOrderCartReturnInfo.conditions
                };
                param.params.cartId = param.params.cartId.trim();
                param.params.state = param.params.state.trim();
                param.params.prodName = param.params.prodName.trim();
                //发送get请求
                vc.http.apiGet('/refundOrder.queryRefundOrders',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.storeOrderCartReturnInfo.total = _json.total;
                        $that.storeOrderCartReturnInfo.records = _json.records;
                        $that.storeOrderCartReturnInfo.orderCarts = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.storeOrderCartReturnInfo.records,
                            dataCount: $that.storeOrderCartReturnInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _queryOrdersMethod: function () {
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetOrdersMethod: function () {
                $that.storeOrderCartReturnInfo.conditions.cartId = "";
                $that.storeOrderCartReturnInfo.conditions.state = "";
                $that.storeOrderCartReturnInfo.conditions.prodName = "";
                $that._listOrders(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _openOrderDetailModel: function (_order) {
                vc.jumpToPage('/#/pages/goods/storeOrderCartDetail?orderId=' + _order.orderId + '&cartId=' + _order.cartId);
            },
            _closeStoreOrderCartModal: function () {
                $("#storeOrderCartReturnModal").modal('hide');
            },
            _openAuditReturnOrderCartModel: function (order) {
                $that.storeOrderCartReturnInfo.curOrderCart = order;
                vc.emit('audit', 'openAuditModal', {});
            },
            _doOpenAuditReturnOrderCartModel: function (_param) {
                //发送get请求
                let _data = {
                    state: _param.state,
                    message: _param.remark,
                    returnId: $that.storeOrderCartReturnInfo.curOrderCart.returnId,
                    shopId: vc.getCurrentCommunity().shopId
                }
                vc.http.apiPost('/storeOrderCartReturn.auditStoreOrderCartReturn',
                    JSON.stringify(_data),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let sendResult = JSON.parse(json);
                        if (sendResult.code == 0) {
                            vc.emit('storeOrderCartReturn', 'list', {});
                            vc.toast('审核成功');
                            return;
                        }
                        vc.toast(sendResult.msg);
                        return;
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _applyReturnOrderCart: function () {
                vc.jumpToPage('/#/pages/goods/applyReturnOrderrCartManage')
            },
            _applyReturnOrder: function () {
                vc.jumpToPage('/#/pages/goods/applyReturnOrderManage')
            }
        }
    });
})(window.vc);
